package cn.lingyangwl.agile.msg.push.service.impl;

import cn.lingyangwl.agile.msg.push.api.MsgPushApi;
import cn.lingyangwl.agile.msg.push.api.constatnts.*;
import cn.lingyangwl.agile.msg.push.api.model.rqrs.CheckAuthUserCaptchaReq;
import cn.lingyangwl.agile.msg.push.api.model.rqrs.MsgPushParam;
import cn.lingyangwl.agile.msg.push.api.model.rqrs.CheckNoAuthUserCaptchaReq;
import cn.lingyangwl.agile.msg.push.api.model.rqrs.SendCaptchaMsgReq;
import cn.lingyangwl.agile.msg.push.core.propcess.MsgPushProcess;
import cn.lingyangwl.agile.msg.push.service.*;
import cn.lingyangwl.framework.validation.ValidationUtils;
import com.github.yitter.idgen.YitIdHelper;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shenguangyang
 */
@Primary
@Service
public class MsgPushApiImpl implements MsgPushApi {
    @Resource
    private MsgPushProcess msgPushHandler;

    @Resource
    private CaptchaMessageService captchaMessageService;
    @Resource
    private NoticeChannelService noticeChannelService;

    @Override
    public void push(MsgPushParam req) {
        ValidationUtils.validateAll(req);
        msgPushHandler.push(req, String.valueOf(YitIdHelper.nextId()));
    }

    @Override
    public void checkNoAuthUserCaptcha(CheckNoAuthUserCaptchaReq req) {
        captchaMessageService.checkNoAuthUserCaptcha(req);
    }

    @Override
    public void checkAuthUserCaptcha(CheckAuthUserCaptchaReq req) {
        captchaMessageService.checkAuthUserCaptcha(req);
    }

    @Override
    public void sendNoAuthUserCaptcha(SendCaptchaMsgReq req) {
        captchaMessageService.sendNoAuthUserCaptcha(req);
    }

    @Override
    public List<String> listTemplateIdsByCodes(NoticeCodeEnum... noticeCodes) {
        List<String> list = Arrays.stream(noticeCodes).map(NoticeCodeEnum::getCode).collect(Collectors.toList());
        return noticeChannelService.listTemplateIdsByCodes(list);
    }

}
